﻿package com.gengine.resource.loader.thread
{
    import com.gengine.resource.info.*;
    import com.gengine.resource.mutiThread.*;
    import com.gengine.resource.mutiThread.vo.*;
    import flash.events.*;
    import flash.net.*;
    import flash.utils.*;

    public class ThreadLoaderObj extends Object
    {
        public var path:String;
        public var transType:int;
        public var callBackId:int;
        public var subCallBackId:int;
        private var _callBack:Function;
        private var _urlLoader:URLLoader;
        private static const _hasTestLoad:Dictionary = new Dictionary(false);

        public function ThreadLoaderObj()
        {
            return;
        }// end function

        public function loadImageUseThread(param1:ImageInfo, param2:Function) : void
        {
            this.path = param1.path;
            this.transType = ThreadTransType.ImageInfo;
            this._callBack = param2;
            if (!this._urlLoader)
            {
                this._urlLoader = new URLLoader();
                this._urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
                this._urlLoader.addEventListener(Event.COMPLETE, this.onCompleteHandler);
                this._urlLoader.addEventListener(IOErrorEvent.IO_ERROR, this.onIOErrorHandler);
                this._urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onIOErrorHandler);
            }
            var _loc_3:* = _hasTestLoad[this.path];
            if (_loc_3 == 1)
            {
                this.onCompleteHandler(null);
            }
            else if (_loc_3 == -1)
            {
                this.onIOErrorHandler(null);
            }
            else
            {
                this._urlLoader.load(new URLRequest(this.path));
            }
            return;
        }// end function

        private function onCompleteHandler(event:Event) : void
        {
            _hasTestLoad[this.path] = 1;
            ThreadManager.instance.sendMessageToSub(this, this.callBackHander);
            return;
        }// end function

        private function onIOErrorHandler(event:Event) : void
        {
            _hasTestLoad[this.path] = -1;
            this.callBackHander(null);
            return;
        }// end function

        private function callBackHander(param1:ImageLoadVo) : void
        {
            var _loc_2:* = this._callBack;
            this._callBack = null;
            if (_loc_2 != null)
            {
                this._loc_2(param1);
            }
            return;
        }// end function

    }
}
